package com.lax.advertmgt.controller.sys;

import com.alibaba.fastjson.JSON;
import com.lax.advertmgt.api.sys.SysService;
import com.lax.advertmgt.constant.ADMGTConstant;
import com.lax.advertmgt.exception.MgtException;
import com.lax.advertmgt.exception.MgtExprInfo;
import com.lax.advertmgt.utils.Result;
import com.lax.advertserver.bo.sys.UserInfoBo;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = ADMGTConstant.BASE_PATH)
public class SysUserController {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SysService sysService;

    @RequestMapping(value = ADMGTConstant.REG_USER_INTO, method = RequestMethod.POST)
    public Result regUserInfo(@RequestBody UserInfoBo userInfoBo) throws MgtException {
        if (userInfoBo == null || StringUtils.isEmpty(userInfoBo.getUserName()) || StringUtils.isEmpty(userInfoBo.getPassword())) {
            throw MgtException.instance(MgtExprInfo.PARAM_NULL);
        }
        logger.info(">>>>>>>>>>>用户注册：{}", JSON.toJSONString(userInfoBo));
        UserInfoBo bo =  sysService.regUserInfo(userInfoBo);
        return Result.success(bo);
    }

}
